// pages/mine/collect/collect.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      collectList:[],
      pageNum: 1,
      pageSize: 5,

      form:{
        typeDetailId:""
      }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this 
    var postObj = {
      url: '/mobileUser/addType/queryMyService?pageNum=' + this.data.pageNum + '&pageSize=' + this.data.pageSize,
      method: 'get'
    }
    app.request.wxRequest(postObj).then(res => {
      if (res.data.code === 200) {
        res.data.rows.forEach((items, i) => {
          items.typeUrl = app.util.config().api + items.typeUrl
        })

        var navList = this.data.collectList
        var rows = res.data.rows
        var allArr = [...navList, ...rows]
        this.setData({
          collectList  : allArr
        })
        that.setData({
          collectList:   res.data.rows
        })

      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that = this
    that.setData({
      pageNum: that.data.pageNum + 1
    })
    that.onShow()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

    

  },
  //取消收藏
  quxiao:function(e){
    var that =this
    that.setData({
    'form.typeDetailId':e.currentTarget.dataset.typedetailid
    })
    wx.showModal({
      title: '警告',
      content: '确认删除吗',
      success(res) {
        if (res.confirm) {
          var shanchuList = {
            url: '/mobileUser/addType/deleteMyService' ,
            method: 'post',
            data:that.data.form
          }
          app.request.wxRequest(shanchuList).then(res => {

            if (res.data.code === 200) {
              that.onShow();
            }
          });

        } 
        else if (res.cancel) {
          console.log('用户点击取消')
        }

      }
    })
  }
})